<template>
	<view class="content">
		<f-navbar title="店铺商品" fontColor="#333" fontSize="34" bgColor="#fff">
			<view class="u-flex" slot="left">
				<van-icon name="arrow-left" color="#333" size="20"/>
			</view>
		</f-navbar>
		<view class="contentbox">
			<scroll-view @scrolltolower="lowerBottom" scroll-y="true"
				class="scrollHeight" :style="{marginTop:0+'rpx'}" :scroll-top="scrollTop" :refresher-threshold="100"
				:refresher-triggered="triggered" :scroll-with-animation="true">
			<view class="contentitem" v-for="(item,index) in dataList" :key="index" @click="godetail(item)">
				<view class="contentitemimg">
					<image class="contentitemimg" :src="item.good_img" mode=""></image>
				</view>
				<view class="contentitem_title">
					<view class="contentitem_titleL">{{item.title}}</view>
					<van-icon name="arrow" size="16" color="#bbb"/>
				</view>
				<view class="content_pricebox">
					<view class="content_priceXP">现拼单价￥<text class="XPprice">{{item.now_price}}</text> </view>
					<view class="content_priceZD">最低拼单价:￥{{item.low_price}}</view>
					<view class="content_priceYJ">原价:￥{{item.origin_price}}</view>
				</view>
				<view class="contentYHinfo">{{item.rule_txt}}</view>
				<view class="content_bottom">
					<view class="store_box" @click.stop="onstoredetail(item)">
						<!-- <view class="store_boxicon"></view> -->
						<image class="store_boxicon" :src="imgurl+'store_icon1.png'" mode=""></image>
						<view class="store_boxtxt">店铺</view>
					</view>
					<view class="kefubox">
						<!-- <view class="kefuboxicon"></view> -->
						<image class="kefuboxicon" :src="imgurl+'lianxikefuicon.png'" mode=""></image>
						<view class="kefuboxtxt">客服</view>
					</view>
					<view class="cartbox">
						<view class="cartboxL">加购物车
						<view class="cart_icon" v-if="cartnum!==0">{{cartnum}}</view>
						</view>
						<view class="cartboxR">立即购买</view>
					</view>
					<view class="pintuan">参与拼单</view>
				</view>
			</view>
			

			</scroll-view>

		</view>
	</view>
</template>

<script>
	import fNavbar from '@/uni_modules/f-navbar/components/f-navbar/f-navbar.vue';
	import {getActGoodsInStore,getAllCartNumByToken} from '../../../utils/app.js'
	export default{
		components: {
			fNavbar
		},
		data(){
			return{
				imgurl: getApp().globalData.imgurl,
				storeId:'', // 店铺id
				pages: 1, // 分页数据
				PageSize: 4, // 一页有多少数据
				total: null, // 总条数	
				dataList: [], // 列表数据
				triggered:false, // 设置是否下拉
				scrollTop: 0 ,
				cartnum: '',// 购物车数量
			}
		},
		onLoad(options) {
			this.storeId = options.storeid
			this.getList(true)
			this.getcartnum()
		},
		methods:{
			// 调转到店铺详情
			onstoredetail(e){
				console.log(e);
				uni.navigateTo({
					url:'/pages/storeDetail/storeDetail?storeid='+e.store_id
				})
			},
			// 点击跳转到详情页
			godetail(e){
				uni.navigateTo({
					url: '/pages/goodsDetail/goodsDetail?codeid='+e.code
				})
			},
			// 获取购物车数量
			getcartnum(){
				
				getAllCartNumByToken({
				}).then(res => {
					console.log(res);
					if(res.data!==''){
						this.cartnum = res.data.all_cart_num
					}else {
						this.cartnum=0
					}
					console.log(this.cartnum);
				
				})
			},
			//触底加载
			lowerBottom() {
				// 判断是否还有下一页数据
				// if (this.pages * this.PageSize >= this.total) return person.showMoreData = true
				// 让页码值自增 +1
				// console.log('999');
				// this.pages += 1
				// 重新获取列表数据
				this.getList(false)
			},
			// 下拉刷新
			getFresh() {
				this.triggered = true,
				this.getList(true)
				
			},
			// 获取数据
			getList(isPullDownRefresh) {
				let currPage = 1
				if(!isPullDownRefresh) {
					currPage = this.pages+1
				} else {
					currPage = 1
				}
				getActGoodsInStore({
					store_id: this.storeId,
					page: currPage
				}).then(res => {
					console.log(res);
					if(res.code==1){
						
					uni.hideToast()
					const newdata = res.data.list
					if(isPullDownRefresh){
						this.dataList = newdata
						this.triggered = false
					} else{
						this.dataList=[...this.dataList,...newdata]
					}
					this.pages = res.data.page.current
					console.log(this.pages);
					// this.total = res.data.page.total
					}
				})
			},
		}
	}
</script>

<style>
	page{
		background: #eee;
	}
	.contentitem{
		width: 690rpx;
		/* height: 652rpx; */
		background: #fff;
		margin: 0 auto;
		margin-top: 4rpx;
		margin-bottom: 20rpx;
		border-radius: 10rpx 10rpx 0rpx 0rpx;
	}
	.scrollHeight{
	height: 90vh;
	}
	.contentitemimg{
		width: 690rpx;
		height: 398rpx;
		background: linear-gradient(0deg, #FBEBDC 0%, #E5C2A4 100%);
		border-radius: 10rpx 10rpx 0rpx 0rpx;
	}
	.contentitem_title{
		margin-left: 20rpx;
		display: flex;
		align-items: center;
		margin-top: 20rpx;
	}
	.contentitem_titleL{
		width: 622rpx;
		/* height: 31rpx; */
		font-size: 28rpx;
		font-family: Hiragino Sans GB;
		font-weight: 700;
		color: #333333;
		/* line-height: 70rpx; */
		overflow: hidden;
		white-space: nowrap;
		text-overflow: ellipsis;
	}
	.content_pricebox{
		display: flex;
		align-items: center;
		margin-left: 20rpx;
		margin-top: 17rpx;
	}
	.content_priceXP{
		font-size: 20rpx;
		font-family: Hiragino Sans GB;
		font-weight: 600;
		color: #FF0000;
		margin-right: 20rpx;
	}
	.XPprice{
		font-size: 30rpx
	}
	.content_priceZD{
	background: #FFC2C0;
	border-radius: 5rpx;
	font-size: 20rpx;
	font-family: Hiragino Sans GB;
	font-weight: normal;
	color: #FF5A00;
	padding: 5rpx 10rpx;
	margin-right: 20rpx;
	}
	.content_priceYJ{
		font-size: 20rpx;
		font-family: Hiragino Sans GB;
		font-weight: normal;
		color: #999999;
	
	}
	.contentYHinfo{
		width: 622rpx;
		font-size: 24rpx;
		font-family: Hiragino Sans GB;
		font-weight: normal;
		color: #00A0E9;
		margin-top: 28rpx;
		margin-left: 20rpx;
		/* line-height: 40rpx; */
	}
	.content_bottom{
		width: 100%;
		height: 105rpx;
		background: #FFFFFF;
		display: flex;
		align-items: center;
		/* justify-content: space-between; */
	}
	.store_box{
		display: flex;
		flex-direction: column;
		align-items: center;
		justify-content: center;
		margin-left: 20rpx;
	}
	.store_boxicon{
		width: 32rpx;
		height: 32rpx;
		/* background: #000; */
	}
	.store_boxtxt{
		font-size: 24rpx;
		font-family: Hiragino Sans GB;
		font-weight: normal;
		color: #333333;
		margin-top: 10rpx;
		/* line-height: 45rpx; */
	}
	.kefubox{
		display: flex;
		flex-direction: column;
		align-items: center;
		justify-content: center;
		margin-left: 38rpx;
	}
	.kefuboxicon{
		width: 39rpx;
		height: 31rpx;
		/* background: #000; */
	}
	.kefuboxtxt{
		font-size: 24rpx;
		font-family: Hiragino Sans GB;
		font-weight: normal;
		color: #333333;
		margin-top: 10rpx;
	}
	.cartbox{
		display: flex;
		align-items: center;
		margin-left: 37rpx;
	}
	.cartboxL{
		width: 154rpx;
		height: 64rpx;
		background: #FF9A00;
		border-radius: 32rpx 0rpx 0rpx 32rpx;
		font-size: 28rpx;
		font-family: Hiragino Sans GB;
		font-weight: normal;
		color: #FFFFFF;
		line-height: 64rpx;
		text-align: center;
		position: relative;
	}
	.cart_icon{
			width: 28rpx;
			height: 28rpx;
			background: #FF0000;
			border-radius: 14rpx;
			font-size: 22rpx;
			font-family: Hiragino Sans GB;
			font-weight: normal;
			color: #FFFFFF;
			line-height: 28rpx;
			text-align: center;
			position: absolute;
			top: 5rpx;
			right: 5rpx;
	}
	.cartboxR{
		width: 154rpx;
		height: 64rpx;
		background: #EF0E6C;
		border-radius: 0rpx 32rpx 32rpx 0rpx;
		font-size: 28rpx;
		font-family: Hiragino Sans GB;
		font-weight: normal;
		color: #FFFFFF;
		line-height: 64rpx;
		text-align: center;
	}
	.pintuan{
		width: 154rpx;
		height: 64rpx;
		background: #FF0000;
		border-radius: 32rpx;
		font-size: 34rpx;
		font-family: Hiragino Sans GB;
		font-weight: 700;
		color: #FFFFFF;
		line-height: 64rpx;
		text-align: center;
		margin-left: 20rpx;
	}
		
</style>